package com.yonglian.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yonglian.common.annotation.Log;
import com.yonglian.common.enums.BusinessType;
import com.yonglian.system.domain.CmsActivityPlan;
import com.yonglian.system.service.ICmsActivityPlanService;
import com.yonglian.common.core.controller.BaseController;
import com.yonglian.common.core.domain.AjaxResult;
import com.yonglian.common.utils.poi.ExcelUtil;
import com.yonglian.common.core.page.TableDataInfo;

/**
 * 活动计划Controller
 * 
 * @author gyok
 * @date 2024-06-03
 */
@Controller
@RequestMapping("/system/activityPlan")
public class CmsActivityPlanController extends BaseController
{
    private String prefix = "system/activityPlan";

    @Autowired
    private ICmsActivityPlanService cmsActivityPlanService;

    @RequiresPermissions("system:activityPlan:view")
    @GetMapping()
    public String activityPlan()
    {
        return prefix + "/activityPlan";
    }

    /**
     * 查询活动计划列表
     */
    @RequiresPermissions("system:activityPlan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsActivityPlan cmsActivityPlan)
    {
        startPage();
        List<CmsActivityPlan> list = cmsActivityPlanService.selectCmsActivityPlanList(cmsActivityPlan);
        return getDataTable(list);
    }

    /**
     * 导出活动计划列表
     */
    @RequiresPermissions("system:activityPlan:export")
    @Log(title = "活动计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsActivityPlan cmsActivityPlan)
    {
        List<CmsActivityPlan> list = cmsActivityPlanService.selectCmsActivityPlanList(cmsActivityPlan);
        ExcelUtil<CmsActivityPlan> util = new ExcelUtil<CmsActivityPlan>(CmsActivityPlan.class);
        return util.exportExcel(list, "活动计划数据");
    }

    /**
     * 新增活动计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存活动计划
     */
    @RequiresPermissions("system:activityPlan:add")
    @Log(title = "活动计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsActivityPlan cmsActivityPlan)
    {
        return toAjax(cmsActivityPlanService.insertCmsActivityPlan(cmsActivityPlan));
    }

    /**
     * 修改活动计划
     */
    @RequiresPermissions("system:activityPlan:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsActivityPlan cmsActivityPlan = cmsActivityPlanService.selectCmsActivityPlanById(id);
        mmap.put("cmsActivityPlan", cmsActivityPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动计划
     */
    @RequiresPermissions("system:activityPlan:edit")
    @Log(title = "活动计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsActivityPlan cmsActivityPlan)
    {
        return toAjax(cmsActivityPlanService.updateCmsActivityPlan(cmsActivityPlan));
    }

    /**
     * 删除活动计划
     */
    @RequiresPermissions("system:activityPlan:remove")
    @Log(title = "活动计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsActivityPlanService.deleteCmsActivityPlanByIds(ids));
    }
}
